@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

:: 智习伴项目桌面快捷方式创建脚本
title 智习伴快捷方式创建器

:: 设置颜色
for /f "delims=" %%i in ('echo prompt $E$S ^| cmd') do set "ESC=%%i"
set "GREEN=%ESC%[92m"
set "BLUE=%ESC%[94m"
set "YELLOW=%ESC%[93m"
set "RED=%ESC%[91m"
set "RESET=%ESC%[0m"

cls
echo %BLUE%╔══════════════════════════════════════════════════════════════════════════════╗%RESET%
echo %BLUE%║%RESET%                        智习伴桌面快捷方式创建器                           %BLUE%║%RESET%
echo %BLUE%║%RESET%              Intelligent Learning Assistant Shortcut Creator             %BLUE%║%RESET%
echo %BLUE%╠══════════════════════════════════════════════════════════════════════════════╣%RESET%
echo %BLUE%║%RESET%                                                                              %BLUE%║%RESET%
echo %BLUE%║%RESET%  本脚本将在您的桌面创建智习伴项目的快捷方式，方便快速启动项目。            %BLUE%║%RESET%
echo %BLUE%║%RESET%                                                                              %BLUE%║%RESET%
echo %BLUE%╚══════════════════════════════════════════════════════════════════════════════╝%RESET%
echo.

:: 获取当前用户桌面路径
set "DESKTOP_PATH=%USERPROFILE%\Desktop"
set "PROJECT_PATH=%~dp0"
set "SHORTCUT_NAME=智习伴项目启动器.lnk"
set "SHORTCUT_PATH=%DESKTOP_PATH%\%SHORTCUT_NAME%"

echo %YELLOW%[*] 当前项目路径: %PROJECT_PATH%%RESET%
echo %YELLOW%[*] 桌面路径: %DESKTOP_PATH%%RESET%
echo %YELLOW%[*] 快捷方式路径: %SHORTCUT_PATH%%RESET%
echo.

:: 检查项目启动脚本是否存在
if not exist "%PROJECT_PATH%start_project.bat" (
    echo %RED%[!] 错误: 未找到项目启动脚本 start_project.bat%RESET%
    echo %RED%    请确保在项目根目录下运行此脚本%RESET%
    pause
    exit /b 1
)

echo %YELLOW%[*] 检查Windows Script Host...%RESET%

:: 检查WSH是否可用
cscript //? >nul 2>&1
if %errorlevel% neq 0 (
    echo %RED%[!] 错误: Windows Script Host不可用%RESET%
    pause
    exit /b 1
)

echo %GREEN%[✓] Windows Script Host检查通过%RESET%
echo.

:: 创建VBS脚本来生成快捷方式
set "VBS_FILE=%TEMP%\CreateShortcut.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") > "%VBS_FILE%"
echo sLinkFile = "%SHORTCUT_PATH%" >> "%VBS_FILE%"
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> "%VBS_FILE%"
echo oLink.TargetPath = "%PROJECT_PATH%start_project.bat" >> "%VBS_FILE%"
echo oLink.WorkingDirectory = "%PROJECT_PATH%" >> "%VBS_FILE%"
echo oLink.Description = "智习伴项目启动器" >> "%VBS_FILE%"
echo oLink.IconLocation = "shell32.dll, 15" >> "%VBS_FILE%"
echo oLink.Save >> "%VBS_FILE%"

echo %YELLOW%[*] 正在创建桌面快捷方式...%RESET%

:: 执行VBS脚本创建快捷方式
cscript //nologo "%VBS_FILE%" >nul 2>&1

:: 删除临时VBS文件
del "%VBS_FILE%" >nul 2>&1

:: 检查快捷方式是否创建成功
if exist "%SHORTCUT_PATH%" (
    echo %GREEN%[✓] 桌面快捷方式创建成功！%RESET%
    echo %GREEN%    快捷方式位置: %SHORTCUT_PATH%%RESET%
    echo.
    echo %BLUE%    您现在可以通过桌面快捷方式快速启动智习伴项目。%RESET%
) else (
    echo %RED%[!] 快捷方式创建失败%RESET%
    echo %YELLOW%    您可以手动创建快捷方式:%RESET%
    echo %YELLOW%    1. 右键点击桌面，选择"新建" -> "快捷方式"%RESET%
    echo %YELLOW%    2. 输入位置: %PROJECT_PATH%start_project.bat%RESET%
    echo %YELLOW%    3. 设置名称为"智习伴项目启动器"%RESET%
)

echo.
echo %GREEN%╔══════════════════════════════════════════════════════════════════════════════╗%RESET%
echo %GREEN%║%RESET%                          快捷方式创建完成!                                 %GREEN%║%RESET%
echo %GREEN%╚══════════════════════════════════════════════════════════════════════════════╝%RESET%
echo.

echo %BLUE%按任意键关闭此窗口...%RESET%
pause >nul